var POST_IMAGE_PATH = "../../Images/PostImages/";
var EVENT_IMAGE_PATH = "../../Images/EventImages/";
var AD_IMAGE_PATH = "../../Images/AdImages/";
var ImageId = 0;
var AdId = 0;

function isDefined(variable)
{
  return eval('(typeof('+variable+') != "undefined");');
}

//=====Edit Post===================================================================================

function ciEditPost_ASPxUploadControl_FileUploadComplete(s,e)
{
  s.ClearText();
  if(e.callbackData != "")
  {
    ciEditPost_ASPxImage.SetImageUrl(POST_IMAGE_PATH + e.callbackData);
    ciEditPost_ASPxTextBoxImageName.SetText(e.callbackData);
  }
}

function ciEditPost_ASPxButtonUpload_Click(s,e)
{
  ciEditPost_ASPxUploadControl.UploadFile();
}

//=====End Edit Post===============================================================================

//=====Events======================================================================================

function Events_DeleteImage(imageId, confirmMsg)
{
  var isConfirmed = confirm(confirmMsg);
  if(isConfirmed)
  {
    var parameter = imageId + "|Delete";
    ciEvents_ASPxDataView.PerformCallback(parameter);
  }
}

function Events_UpdateImage(imageId)
{
  var parameter = imageId + "|Load";
  ImageId = imageId;
  ciEvents_ASPxCallbackPanel.PerformCallback(parameter);
}

function ciEvents_ASPxButtonUpdate_Click(s,e)
{
  var parameter = "";
  if(ImageId > 0)
  {
    parameter = ImageId + "|Update|";
    //ciEvents_ASPxButtonClear_Click(null,null);
  }
  else
  {
    parameter = ImageId + "|Add|";
  }
  
  parameter += "<Value>";
  parameter += "<Add Name='ASPxTextBoxImageTitle' Text='" + ciEvents_ASPxTextBoxImageTitle.GetText() + "'/>";
  parameter += "<Add Name='ASPxMemoImageDescription' Text='" + ciEvents_ASPxMemoImageDescription.GetText() + "'/>";
  parameter += "<Add Name='ASPxTextBoxImageLink' Text='" + ciEvents_ASPxTextBoxImageLink.GetText().replace(/[\:]/g,"[") + "'/>";
  parameter += "<Add Name='ASPxTextBoxImageName' Text='" + ciEvents_ASPxTextBoxImageName.GetText() + "'/>";
  parameter += "</Value>";
  
  var flag = isDefined("ciEvents_ASPxDataView");
  if(flag)
    ciEvents_ASPxDataView.PerformCallback(parameter);
    
  if((ImageId == 0) && (flag))
  {
    ciEvents_ASPxButtonClear_Click(null,null);
  }
}

function ciEvents_ASPxButtonClear_Click(s,e)
{
  ciEvents_ASPxTextBoxImageTitle.SetText("");
  ciEvents_ASPxMemoImageDescription.SetText("");
  ciEvents_ASPxTextBoxImageLink.SetText("");
  ciEvents_ASPxUploadControl.ClearText();
  ciEvents_ASPxImage.SetImageUrl("");
  ciEvents_ASPxTextBoxImageName.SetText("");
  ImageId = 0;
}

function ciEvents_ASPxButtonUpload_Click(s,e)
{
  ciEvents_ASPxUploadControl.UploadFile();
}

function ciEvents_ASPxUploadControl_FileUploadComplete(s,e)
{
  s.ClearText();
  if(e.callbackData != "")
  {
    ciEvents_ASPxImage.SetImageUrl(EVENT_IMAGE_PATH + e.callbackData);
    ciEvents_ASPxTextBoxImageName.SetText(e.callbackData);
  }
}

//=====End Events==================================================================================

//=====Ads=========================================================================================

function Ads_DeleteImage(adId, confirmMsg)
{
  var isConfirmed = confirm(confirmMsg);
  if(isConfirmed)
  {
    var parameter = adId + "|Delete";
    ciAds_ASPxDataView.PerformCallback(parameter);
  }
}

function Ads_UpdateImage(adId)
{
  var parameter = adId + "|Load";
  AdId = adId;
  ciAds_ASPxCallbackPanel.PerformCallback(parameter);
}

function ciAds_ASPxButtonUpdate_Click(s,e)
{
  var parameter = "";
  if(AdId > 0)
  {
    parameter = AdId + "|Update|";
    //ciEvents_ASPxButtonClear_Click(null,null);
  }
  else
  {
    parameter = AdId + "|Add|";
  }
  
  parameter += "<Value>";
  parameter += "<Add Name='ASPxTextBoxImageTitle' Text='" + ciAds_ASPxTextBoxImageTitle.GetText() + "'/>";
  parameter += "<Add Name='ASPxTextBoxImageLink' Text='" + ciAds_ASPxTextBoxImageLink.GetText().replace(/[\:]/g,"[") + "'/>";
  parameter += "<Add Name='ASPxTextBoxImageName' Text='" + ciAds_ASPxTextBoxImageName.GetText() + "'/>";
  parameter += "<Add Name='ASPxTextBoxIndex' Text='" + ciAds_ASPxTextBoxIndex.GetText() + "'/>";
  
  parameter += "</Value>";
  
  var flag = isDefined("ciAds_ASPxDataView");
  if(flag)
  {
    ciAds_ASPxDataView.PerformCallback(parameter);
  }
    
  if((AdId == 0) && (flag))
  {
    ciAds_ASPxButtonClear_Click(null,null);
  }
}

function ciAds_ASPxButtonClear_Click(s,e)
{
  ciAds_ASPxTextBoxImageTitle.SetText("");
  //ciEvents_ASPxMemoImageDescription.SetText("");
  ciAds_ASPxTextBoxImageLink.SetText("");
  ciAds_ASPxUploadControl.ClearText();
  ciAds_ASPxImage.SetImageUrl("");
  ciAds_ASPxTextBoxImageName.SetText("");
  ciAds_ASPxTextBoxIndex.SetText("");
  ImageId = 0;
}

function ciAds_ASPxButtonUpload_Click(s,e)
{
  ciAds_ASPxUploadControl.UploadFile();
}

function ciAds_ASPxUploadControl_FileUploadComplete(s,e)
{
  s.ClearText();
  if(e.callbackData != "")
  {
    ciAds_ASPxImage.SetImageUrl(AD_IMAGE_PATH + e.callbackData);
    ciAds_ASPxTextBoxImageName.SetText(e.callbackData);
  }
}

//=====End Ads=====================================================================================